import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
class Testing extends JFrame
{
  DefaultListModel listModel = new DefaultListModel();
  JList list = new JList(listModel);
  public Testing()
  {
    setLocation(400,300);
    setDefaultCloseOperation(EXIT_ON_CLOSE);
    JPanel jp = new JPanel();
    JScrollPane sp = new JScrollPane(list);
    sp.setPreferredSize(new Dimension(100,200));
    jp.add(sp);
    getContentPane().add(jp);
    pack();
    listModel.addElement(new QueryResult(1,"project 1"));
    listModel.addElement(new QueryResult(2,"project 2"));
    listModel.addElement(new QueryResult(16,"project 3"));
    list.addMouseListener(new MouseAdapter(){
      public void mouseClicked(MouseEvent me){
        QueryResult temp = (QueryResult)list.getSelectedValue();
        if(temp != null)
        {
          JOptionPane.showMessageDialog(Testing.this,temp.recordNumber + " - "+temp.description);
        }}});
  }
  public static void main(String[] args){new Testing().setVisible(true);}
}
class QueryResult
{
  int recordNumber;
  String description;
  public QueryResult(int rn, String desc)
  {
    recordNumber = rn;
    description = desc;
  }
  public String toString(){return description;}
}

